package util.bio.annotation;
import java.io.*;
import java.util.*;

public class ScoredStartStop extends StartStop{
	//fields
	private float score;

	//constructor
	public ScoredStartStop (int start, int stop, float score){
		super(start, stop);
		this.score = score;
	}

	//methods
	public String toString(){
		return start+"\t"+end+"\t"+score;
	}

	public float getScore() {
		return score;
	}

	public void setScore(float score) {
		this.score = score;
	}

	/**Loads a binary file containing int,int,float (start,stop,score)
	 * @return an UNSORTED array! or null if something bad happened.*/
	public static ScoredStartStop[] loadBinary(File binaryFile){
		ArrayList<ScoredStartStop> sss = new ArrayList<ScoredStartStop>(10000);
		DataInputStream dis = null;
		try {
			dis = new DataInputStream(new BufferedInputStream(new FileInputStream(binaryFile)));
			while (true){
				int start = dis.readInt();
				int stop = dis.readInt();
				float score = dis.readFloat();
				sss.add(new ScoredStartStop(start,stop,score));
			}

		} catch (EOFException eof){
			ScoredStartStop[] s = new ScoredStartStop[sss.size()];
			sss.toArray(s);
			return s;
		}
		catch (Exception e){
			e.printStackTrace();
			return null;
		} finally {
			if (dis != null) {
				try {
					dis.close();
				} catch (IOException ignored) {
				}
			}
		}
	}


}
